% In this function we will build the mask for all the image based on image_0009.jpg.
%
%
% The basic idea is:
% 
% first, we only consider to segment the lower half of the
% image. we cut off the lower half of the image0009.jpg and use this image
% as our background.
%
% second, we deduct all our model from all the image from the folder. In
% this case, the background part will become zero or nearlly zero, and the
% foreground part will become not zero or a value far from zero. 
%
% third, we set a threshold, the value below this threshold will be all set
% to zero, and the value above this threshold will be all set to one. After
% this step, it means we already finished our mask.
%
% finally, we can mutiple our mask with the original image and get the
% clear segmented foreground.
%
% The usage of the function:


% read the image from the image folder and retrive the lower part of mask.
in = imread('image_folder1/image_0009.jpg', 'jpg');


maskTmp = in(121:240,:,:);

maskUp = zeros(120,352,3);

maskFinal = [maskUp;maskTmp];

figure();
imshow(maskFinal);
imwrite(maskFinal, 'mask/mask.jpg', 'jpg');
